package com.minyon_web_admin.service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.minyon_web_admin.common.utils.StringUtil;
import com.minyon_web_admin.common.bean.ResCode;
import com.minyon_web_admin.common.utils.ResponseUtil;
import com.minyon_web_admin.common.mybatis.MybatisDao;
import com.minyon_web_admin.common.page.PageUtil;
import com.minyon_web_admin.common.base.BaseService;
import com.minyon_web_admin.server.ISysDict;
import com.minyon_web_admin.model.SysDictBean;
/**
 * 
 * <br>
 * <b>功能：</b>SysDictService<br>
 */
 @Service
public class SysDictService  extends BaseService implements ISysDict  {

protected final Logger minYonlogger = (Logger) LoggerFactory
			.getLogger(getClass());
	@Autowired
	MybatisDao mybatisDao;
	
	
		@Override
	public Map<String, Object> getListPage(Map<String, Object> reqMap) {
		minYonlogger.info("查询分页列表");
		PageUtil<SysDictBean> page = new PageUtil<SysDictBean>(reqMap);
		reqMap.put("page", page);
		Map<String, Object> resMap = new HashMap<String, Object>();
		List<SysDictBean> list = mybatisDao.getList("SysDictMapper.listPageSysDict",
				reqMap);
		if (list.size() > 0) {
			page.setResult(list);
			resMap.put("RESULT", page);
			return ResponseUtil.FormatResMsg(ResCode.SUCCESS, "",
					ResCode.SUCCESS_QUERY_MSG, resMap, false);
		} else {
			return ResponseUtil.FormatResMsg(ResCode.FAILD,
					ResCode.EXPECT_NOT_MATCH, "暂无数据", resMap, false);
		}
	}
	@Override
	public Map<String, Object> queryListInfo(Map<String, Object> reqMap) {
	Map<String, Object> resMap = new HashMap<String, Object>();
	  List<SysDictBean> list = mybatisDao.getList("SysDictMapper.queryListInfo",
				reqMap);
		if (list.size() > 0) {
			resMap.put("RESULT", list);
			return ResponseUtil.FormatResMsg(ResCode.SUCCESS, "",
					ResCode.SUCCESS_QUERY_MSG, resMap, false);
		} else {
			return ResponseUtil.FormatResMsg(ResCode.FAILD,
					ResCode.EXPECT_NOT_MATCH, "暂无数据", resMap, false);
		}
	}
	@Override
	public Map<String, Object> queryDetail(Map<String, Object> reqMap) {
	Map<String, Object> resMap = new HashMap<String, Object>();
	  SysDictBean bean = mybatisDao.get("SysDictMapper.queryDetail",
				reqMap);
		if (StringUtil.isNotEmpty(bean)) {
			resMap.put("RESULT", bean);
			return ResponseUtil.FormatResMsg(ResCode.SUCCESS, "",
					ResCode.SUCCESS_QUERY_MSG, resMap, false);
		} else {
			return ResponseUtil.FormatResMsg(ResCode.FAILD,
					ResCode.EXPECT_NOT_MATCH, "暂无数据", resMap, false);
		}
	}
	@Override
	public Map<String, Object> deleteInfo(String id) {
		minYonlogger.info("删除数据");		 
		Map<String, Object> resMap = new HashMap<String, Object>();
		int flag = mybatisDao.delete("SysDictMapper.deleteInfo",
				id);       
		if (flag>0) {
			resMap.put("RESULT", flag);
			return ResponseUtil.FormatResMsg(ResCode.SUCCESS, "",
					ResCode.SUCCESS_DELETE_MSG, resMap, false);
		} else {
			return ResponseUtil.FormatResMsg(ResCode.FAILD,
					ResCode.EXPECT_NOT_MATCH, "删除失败", resMap, false);
		}
	}
	
	 @Override
	public Map<String, Object> insertInfo(SysDictBean bean) {
		minYonlogger.info("新增数据");		 
		Map<String, Object> resMap = new HashMap<String, Object>();
		int flag = mybatisDao.insert("SysDictMapper.insertInfo",
				bean);       
		if (flag>0) {
			resMap.put("RESULT", flag);
			return ResponseUtil.FormatResMsg(ResCode.SUCCESS, "",
					ResCode.SUCCESS_INSERT_MSG, resMap, false);
		} else {
			return ResponseUtil.FormatResMsg(ResCode.FAILD,
					ResCode.EXPECT_NOT_MATCH, "添加失败", resMap, false);
		}
	}
	
	 @Override
	public Map<String, Object> updateInfo(SysDictBean bean) {
		minYonlogger.info("更新数据");		 
		Map<String, Object> resMap = new HashMap<String, Object>();
		int flag = mybatisDao.update("SysDictMapper.updateSelective",
				bean);       
		resMap.put("RESULT", flag);
		if (flag>0) {
			return ResponseUtil.FormatResMsg(ResCode.SUCCESS, "",
					ResCode.SUCCESS_UPDATE_MSG, resMap, false);
		} else {
			return ResponseUtil.FormatResMsg(ResCode.FAILD,
					ResCode.EXPECT_NOT_MATCH, "更新失败", resMap, false);
		}
	}
}
